import { Form, Input, Button, Checkbox, message } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import axios from 'axios'
import './index.css'
import logo from '../../assets/logo.png'
const Login = ({ history }) => {
    const onFinish = async values => {
        // console.log('Received values of form: ', values);
        const { mobile, code } = values
        try {
            const res = await axios.post('http://geek.itheima.net/v1_0/authorizations', {
                mobile,
                code
            })
            localStorage.setItem('geek-87', res.data.data.token)
            message.success('登陆成功', 1, () => {
                history.push('/home')
            })
        } catch (error) {
            message.warning(error.response.data.message, 1)
        }
    }
    return (
        <div className='login'>
            <div className='login-content'>
                <div>
                    <img className='img' src={logo} alt="" />
                </div>
                <Form
                    size='large'
                    name="normal_login"
                    className="login-form"
                    initialValues={{ remember: true, mobile: '13456789102', code: '246810' }}
                    onFinish={onFinish}
                >
                    <Form.Item
                        name="mobile"
                        rules={[{ required: true, message: '请输入正确的手机号码!' }]}
                    >
                        <Input placeholder="请输入手机号" />
                    </Form.Item>
                    <Form.Item
                        name="code"
                        rules={[{ required: true, message: '请输入正确的验证码!' }]}
                    >
                        <Input
                            type="password"
                            placeholder="请输入验证码"
                        />
                    </Form.Item>
                    <Form.Item>
                        <Form.Item name="remember" valuePropName="checked" noStyle>
                            <Checkbox>小伙砸,先过来签一份协议</Checkbox>
                        </Form.Item>

                    </Form.Item>

                    <Form.Item>
                        <Button block type="primary" htmlType="submit" className="login-form-button">
                            登录
                        </Button>

                    </Form.Item>
                </Form>
            </div>
        </div>
    )
}

export default Login
